import { request } from '../utils/request';

// API统计概览接口
export interface ApiStatisticsOverview {
    totalApiCount: number;
    restApiCount: number;
    dubboApiCount: number;
    highRiskApiCount: number;
    activeApiCount: number;
    avgDeprecationScore: number;
    totalRiskApiCount: number;
    activityRate: number;
}

// API类型分布接口
export interface ApiTypeDistribution {
    type: string;
    count: number;
    percentage: number;
    displayName: string;
}

// 风险等级分布接口
export interface RiskLevelDistribution {
    level: string;
    count: number;
    percentage: number;
    displayName: string;
}

// 风险分数区间接口
export interface RiskScoreRange {
    range: string;
    count: number;
    minScore: number;
    maxScore: number;
}

// API风险分析接口
export interface ApiRiskAnalysis {
    riskDistribution: RiskLevelDistribution[];
    totalHighRisk: number;
    totalLowRisk: number;
    avgRiskScore: number;
    scoreRanges: RiskScoreRange[];
}

// 类类型分布接口
export interface ClassTypeDistribution {
    classType: string;
    count: number;
    percentage: number;
    displayName: string;
}

// API分类统计接口
export interface ApiClassificationStats {
    interfaceCount: number;
    implementationCount: number;
    regularClassCount: number;
    abstractClassCount: number;
    unidentifiedCount: number;
    distribution: ClassTypeDistribution[];
}

// 获取API统计概览
export async function getApiStatisticsOverview(unitId: string): Promise<ApiStatisticsOverview> {
    const response = await request({
        url: `/api/statistics/overview/${unitId}`,
        method: 'get'
    });
    return response.data; // 提取实际数据部分
}

// 获取API类型分布
export async function getApiTypeDistribution(unitId: string): Promise<ApiTypeDistribution[]> {
    const response = await request({
        url: `/api/statistics/type-distribution/${unitId}`,
        method: 'get'
    });
    return response.data; // 提取实际数据部分
}

// 获取API风险分析
export async function getApiRiskAnalysis(unitId: string): Promise<ApiRiskAnalysis> {
    const response = await request({
        url: `/api/statistics/risk-analysis/${unitId}`,
        method: 'get'
    });
    return response.data; // 提取实际数据部分
}

// 获取API分类统计
export async function getApiClassificationStats(unitId: string): Promise<ApiClassificationStats> {
    const response = await request({
        url: `/api/statistics/classification-stats/${unitId}`,
        method: 'get'
    });
    return response.data; // 提取实际数据部分
}